<?php
	require_once("../conexion/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />
<script src="../include_js/jquery.js" type="text/javascript"></script>
<style>
.filaPar
{
	background:#81D371; 
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
.filaImpar
{
	background:#AEF1A1;
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
</style>
<script>
function Formulario(valor)
{
	
	numero = document.getElementById("tbINFA").rows[valor].cells[0].innerText;
	//fecha = document.getElementById("tbDIA").rows[valor].cells[2].innerText;
	//Codarea = document.getElementById("tablaFactura").rows[valor].cells[2].innerText;
	//alert(Codarea);
	window.open("Contabilidad/Ventana_Resumen_Factura_Infa.php?fac="+numero,"VentanaFacturaInfa","width=810,height=550,scrollbars=yes");
}
</script>
</head>

<body>
 <?php
 	extract($_POST);

	$cont = 0;
	
 	if ($txtFactura2=="")
	{
		$txtFactura2="null";
		$cont++;
	}
	else
	{$txtFactura2="'".$txtFactura2."'";}
	
	if ($cmb_Cliente2=='0') {
		$cmb_Cliente2="null";
		$cont++;
	}
	else
	{$cmb_Cliente2="'".$cmb_Cliente2."'";}
	
	if ($txtFIni==""){
		$txtFIni="null";
		$cont++;
	}
	else
	{
		$FechaIni = explode("-", $txtFIni);
		$txtFIni = "$FechaIni[2]-$FechaIni[1]-$FechaIni[0]";
	}
	
	if ($txtFFin==""){
		$txtFFin="null";
		$cont++;
	}
	else
	{
		$FechaFin = explode("-", $txtFFin);
		$txtFFin = "$FechaFin[2]-$FechaFin[1]-$FechaFin[0]";
	}
	
	
 	if($cont != 4)
	{
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql = "select
				FacInfaNumFac,
				InfaCodCentro,
				CliRSocial,
				FacInfaUF,
				FacInfaMonto,
				date_format(FacInfaFecha,'%d/%m/%Y') as fecha,
				FacInfaEstado
				from facturainfa
				inner join infa on
				facturainfa.InfaCod=infa.InfaCod
				inner join clientes on
				clientes.CliRut=facturainfa.CliRut
				
				where
				(($txtFactura2 is NULL) or (FacInfaNumFac = $txtFactura2)) and
				(($cmb_Cliente2 is NULL) or (facturaInfa.CliRut = $cmb_Cliente2)) and
				((($txtFIni is NULL) and ($txtFFin is NULL)) or DATE(FacInfaFecha) BETWEEN '".$txtFIni."' and '".$txtFFin."')";
				//echo $sql;
			$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
			$fila = mysql_num_rows($res);
			if($fila >0)
			{?>
				<table width="100%" border="0" class="uno" cellpadding="0" cellspacing="0" id="tbINFA">
				<thead>
  				<tr>
    				<th width="12%">N&deg; Factura</th>
				    <th width="12%">C&Oacute;digo Centro</th>
				    <th width="40%">Cliente</th>
				    <th width="11%">uf</th>
				    <th width="13%">monto ($)</th>
				    <th width="12%">fecha</th>
					<th width="12%">estado</th>
  				</tr>
 				</thead>
				<?php
				$cont=1;
				$aux=1;
				while($reg = mysql_fetch_array($res))
				{
					if(($cont % 2)==0)
					{
						echo "<tr class=\"filaPar\" id=\"".$aux."\">";
						echo "<td width=\"12%\" class=\"filaPar\"><a href=javascript:Formulario($aux);>".$reg['FacInfaNumFac']."</a></td>";
						echo "<td width=\"12%\" class=\"filaPar\">".$reg['InfaCodCentro']."</td>";
						echo "<td width=\"40%\" class=\"filaPar\">".$reg['CliRSocial']."</td>";
						echo "<td width=\"11%\" class=\"filaPar\">".$reg['FacInfaUF']."</td>";
						echo "<td width=\"13%\" class=\"filaPar\">$".number_format ($reg['FacInfaMonto'],0,',','.')."</td>";
						echo "<td width=\"12%\" class=\"filaPar\">".$reg['fecha']."</td>";
						echo "<td width=\"12%\" class=\"filaPar\">".$reg['FacInfaEstado']."</td>";
						echo "</tr>";
					}
					else
					{
						echo "<tr class=\"filaImpar\" id=\"".$aux."\">";
						echo "<td width=\"12%\" class=\"filaImpar\"><a href=javascript:Formulario($aux);>".$reg['FacInfaNumFac']."</a></td>";
						echo "<td width=\"12%\" class=\"filaImpar\">".$reg['InfaCodCentro']."</td>";
						echo "<td width=\"40%\" class=\"filaImpar\">".$reg['CliRSocial']."</td>";
						echo "<td width=\"11%\" class=\"filaImpar\">".$reg['FacInfaUF']."</td>";
						echo "<td width=\"13%\" class=\"filaImpar\">$".number_format ($reg['FacInfaMonto'],0,',','.')."</td>";
						echo "<td width=\"12%\" class=\"filaImpar\">".$reg['fecha']."</td>";
						echo "<td width=\"12%\" class=\"filaImpar\">".$reg['FacInfaEstado']."</td>";
						echo "</tr>";
					}
					$cont++;
					$aux++;
				}
				$con->cerrarBD();
				?></table><?php
			}
			else
				{echo "<label style=\"font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;\">La b&uacute;squeda no gener&oacute; resultados.</label>";}
	}
?>
</body>
</html>
